import {defineStore} from "pinia";
import axios from "axios";


export const useStore = defineStore('general', {
    state: () => {
        return {
            user: {
                id: 0,
                username: '',
                email: '',
                role: '',
                registerTime: null,
                avatar: ''
            }, forum: {
                types: []
            }
        }
    }, getters: {
        avatarUrl() {
            if (this.user.avatar) {
                //自动发起请求
                return `${axios.defaults.baseURL}/images${this.user.avatar}`
            } else {
                return "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
            }
        }
    }, actions: {
        findTypeById(id) {
            for (let type of this.forum.types) {
                if (type.id === id) {
                    return type
                }
            }
        }
    }
})